package com.ruoyi.my.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.WebTakeTime;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.my.domain.GrInterview;
import com.ruoyi.my.service.IGrInterviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 面试Controller
 *
 * @author liuxusheng
 * @date 2022-01-13
 */
@RestController
@RequestMapping("/my/interview")
public class GrInterviewController extends BaseController {
    @Autowired
    private IGrInterviewService grInterviewService;

    /**
     * 查询面试列表
     */

    @WebTakeTime
    @PreAuthorize("@ss.hasPermi('my:interview:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrInterview grInterview) {
        startPage();
        List<GrInterview> list = grInterviewService.selectGrInterviewList(grInterview);
        return getDataTable(list);
    }

    /**
     * 导出面试列表
     */
    @PreAuthorize("@ss.hasPermi('my:interview:export')")
    @Log(title = "面试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrInterview grInterview) {
        List<GrInterview> list = grInterviewService.selectGrInterviewList(grInterview);
        ExcelUtil<GrInterview> util = new ExcelUtil<GrInterview>(GrInterview.class);
        util.exportExcel(response, list, "面试数据");
    }

    /**
     * 获取面试详细信息
     */
    @PreAuthorize("@ss.hasPermi('my:interview:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(grInterviewService.selectGrInterviewById(id));
    }

    /**
     * 新增面试
     */
    @PreAuthorize("@ss.hasPermi('my:interview:add')")
    @Log(title = "面试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrInterview grInterview) {
        return toAjax(grInterviewService.insertGrInterview(grInterview));
    }

    /**
     * 修改面试
     */
    @PreAuthorize("@ss.hasPermi('my:interview:edit')")
    @Log(title = "面试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrInterview grInterview) {
        return toAjax(grInterviewService.updateGrInterview(grInterview));
    }

    /**
     * 删除面试
     */
    @PreAuthorize("@ss.hasPermi('my:interview:remove')")
    @Log(title = "面试", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(grInterviewService.deleteGrInterviewByIds(ids));
    }
}
